package com.example.online_exam_system.controller;

import com.example.online_exam_system.entity.Subject;
import com.example.online_exam_system.service.SubjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 管理科目的Controller
 */
@RestController
@Slf4j
public class SubjectController {
    //注入subjectService
    @Autowired
    private SubjectService subjectService;

    /**
     * 添加科目
     * @param subject
     */
    @PostMapping("/addSubject")
    @ResponseBody
    public Map<String, Object> addSubject(@RequestBody Subject subject){
        Map<String,Object> map = null;
            try {
                map = subjectService.addSubject(subject);
            }catch (Exception e){
                map.put("success",false);
                map.put("errMsg",e.getMessage());
            }
            return map;
    }
    /**
     * 添加科目
     * @param subject
     */
    @PostMapping("/deleteSubject")
    @ResponseBody
    public Map<String, Object> deleteSubject(@RequestBody Subject subject){
        Map<String,Object> map = null;
        try {
            map = subjectService.updateSubStatus(subject);
        }catch (Exception e){
            map.put("success",false);
            map.put("data",e.getMessage());
        }
        return map;
    }
}
